/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminFilm.java
 *
 * Created on Apr 30, 2012, 11:17:54 AM
 */
package GUI.Admin;

import dao.HinhAnhDAO;
import dao.LoaiPhimDAO;
import dao.PhimDAO;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.ActionMap;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import main.MainFormApp;
import org.jdesktop.application.Application;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.Task;
import pojo.Hinhanh;
import pojo.Loaiphim;
import pojo.Phim;
import utils.BusyIndicator;
import utils.BusyIndicatorInputBlocker;
import utils.ClassUtils;
import utils.ClassUtils.StateFields;

/**
 *
 * @author Hnmtuan
 */
public class AdminFilm extends javax.swing.JPanel {

    // <editor-fold defaultstate="collapsed" desc="Define all variables using this application">
    private SingleFrameApplication localApplication;
    private ActionMap _rsActionMap;
    private DefaultTableModel _filmModel;
    private List<Phim> _films;
    private List<ClassUtils.FilmVersions> _versions;
    private List<Loaiphim> _categories;
    private boolean saveNeeded, cancelSelected, newRow;
    private BusyIndicator localBusy;
    private static int DETAILED_PANEL_WIDTH = 600;
    private static int DETAILED_PANEL_HEIGHT = 30;
    private static int DETAIL_SCROLL_GAP_SIZE = 19;
    private static int DEFAULT_INDEX_COMBO = 0;
    private String DEFAULT_SEARCH_STRING;
    private AdminImageDialog _imagesDialog;
    // </editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Define messages and error messages" >
    private final String MSG_EMPTY = "";
    private final String MSG_LOADING = "Reloading list film types  .... !";
    private final String MSG_SAVE_SUCCESS = "Insert film successfully";
    private final String MSG_SAVE_BEGINNING = "Begin saving .... !";
    private final String MSG_SAVE_DATABASE = "Saving database  .... !";
    private final String MSG_UPDATE_SUCCESS = "Update film successfully";
    private final String MSG_UPDATE_BEGINNING = "Begin updating .... !";
    private final String MSG_UPDATE_DATABASE = "Updating database  .... !";
    private final String MSG_DELETE_SUCCESS = "Delete film type successfully";
    private final String MSG_DELETE_BEGINNING = "Begin deleteing .... !";
    private final String MSG_DELETE_DATABASE = "Deleteing database  .... !";
    private final String MSG_DELETE_CONFIRM = "Do you want to delete %s ?";
    private final String MSG_DELETE_TITLE = "Delete Film Type";
    private final String MSG_SEARCH_BEGINNING = "Begin searching .... !";
    private final String MSG_SEARCH_SUCCESS = "Search successfully .... !";
    private final String MSG_UPLOAD_IMAGES_SUCCESS = "Upload images successfully .... !";
    private final String ERR_LIST_EMPTY = "Type list is empty";
    private final String ERR_LIST_CATEGORIES_EMPTY = "Categories is empty";
    private final String ERR_LIST_VERSIONS_EMPTY = "Versions is empty";
    private final String ERR_SAVE_TASK = "Save task not done !";
    private final String ERR_SELECT_OUTOFBOUND = "You select out of bound !";
    private final String ERR_SELECTED_TYPE_EMPTY = "Selected type is empty";
    private final String ERR_INVALID_PARAMS = "Invalid parameters !";
    private final String ERR_UPDATE_INVALID_PARAMS = "Update invalid parameters !";
    private final String ERR_UPDATE_TASK = "Update task not done !";
    private final String ERR_DELETE_INVALID_PARAMS = "Delete invalid parameters !";
    private final String ERR_DELETE_TASK = "Delete task not done !";
    private final String ERR_SEARCH_INVALID_PARAMS = "Search invalid parameters !";
    private final String ERR_SEARCH_INVALID_SOURCES = "Source search empty !";
    private final String ERR_SEARCH_NOT_FOUND = "%s not found !";
    private final String ERR_SEARCH_TASK = "Search task not done !";
    private final String ERR_NOT_SELECTED_FILM = "Nothing film is selected !";
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Constructor" >

    public AdminFilm(SingleFrameApplication appContext, BusyIndicator busy) throws Exception {
        localApplication = appContext;
        localBusy = busy;
        initComponents();
        initActions();
        loadVersions();
        loadCategories();
        loadFilms();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Init Actions" >
    private void initActions() throws Exception {
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminFilm");
        _rsActionMap = Application.getInstance(main.MainFormApp.class).getContext().getActionMap(getClass(), this);
        jbtnSearch.setAction(_rsActionMap.get("searchFilms"));
        jbtnReset.setAction(_rsActionMap.get("resetRow"));
        jbtnAdd.setAction(_rsActionMap.get("addRow"));
        jbtnUpdate.setAction(_rsActionMap.get("updateRow"));
        jbtnDelete.setAction(_rsActionMap.get("deleteRow"));
        jbtnCancel.setAction(_rsActionMap.get("cancelRow"));
        jbtnChangeImages.setAction(_rsActionMap.get("changeImages"));
        setNewRow(true);
        DEFAULT_SEARCH_STRING = bundle.getString("jtfSearchFilm.title");
        jtbFilms.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            // -->>> not revoiked event throws exception

            public void valueChanged(ListSelectionEvent e) {
                if (isRecordSelected()) {
                    loadFields();
                }
                firePropertyChange("recordSelected", !isRecordSelected(), isRecordSelected());
                setSaveNeeded(true);
                setCancelSelected(true);
                setNewRow(false);
            }
        });
        jtfSearch.addMouseListener(new MouseAdapter() {

            // Compsite of two actions Press and Release
            @Override
            public void mouseClicked(MouseEvent e) {
                String searchText = jtfSearch.getText();
                // if text field empty so on ...
                if (searchText.equalsIgnoreCase(DEFAULT_SEARCH_STRING)) {
                    jtfSearch.setText("");
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                String searchText = jtfSearch.getText();
                // if texfield empty so write default text for it
                if (searchText.equalsIgnoreCase("")) {
                    jtfSearch.setText(DEFAULT_SEARCH_STRING);
                }
                // else nothing else ..
            }
        });
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Actions">    

    @Action(enabledProperty = "recordSelected")
    public Task changeImages() {
        Task task = new ChangeImageTask();
        //task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action
    public Task searchFilms() {
        Task task = new SearchTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action
    public void resetRow() {
        clearAllTextField();
        defaultAllComboBox();
    }

    @Action(enabledProperty = "newRow")
    public Task addRow() {
        Task task = new SaveTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "saveNeeded")
    public Task updateRow() {
        Task task = new UpdateTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "recordSelected")
    public Task deleteRow() {
        Task task = new DeleteTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "cancelSelected")
    public void cancelRow() {
        defaultButtonState();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Property or State">

    public boolean isCancelSelected() {
        return cancelSelected;
    }

    public boolean isSaveNeeded() {
        return saveNeeded;
    }

    public boolean isNewRow() {
        return newRow;
    }

    public boolean isRecordSelected() {
        return jtbFilms.getSelectedRow() != -1;
    }

    public void setSaveNeeded(boolean saveNeeded) {
        if (saveNeeded != this.saveNeeded) {
            this.saveNeeded = saveNeeded;
            firePropertyChange("saveNeeded", !this.saveNeeded, this.saveNeeded);
        }
    }

    public void setCancelSelected(boolean cancelSelected) {
        if (cancelSelected != this.cancelSelected) {
            this.cancelSelected = cancelSelected;
            firePropertyChange("cancelSelected", !this.cancelSelected, this.cancelSelected);
        }
    }

    public void setNewRow(boolean newRow) {
        if (newRow != this.newRow) {
            this.newRow = newRow;
            firePropertyChange("newRow", !this.newRow, this.newRow);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement Actions to GUI" >

    protected final void clearAllTextField() {
        jtfCodeFilm.setText(MSG_EMPTY);
        jtfNameFilm.setText(MSG_EMPTY);
        jtfActorFilm.setText(MSG_EMPTY);
        jtfStudioFilm.setText(MSG_EMPTY);
        jtfNationalFilm.setText(MSG_EMPTY);
        jtfDurationFilm.setText(MSG_EMPTY);
        jtfPirceFilm.setText(MSG_EMPTY);
        jdcStartDateFilm.setDate(null);
        jtaDescriptionFilm.setText(MSG_EMPTY);
    }

    protected final void defaultButtonState() {
        clearAllTextField();
        jtbFilms.clearSelection();
        defaultAllComboBox();
        firePropertyChange("recordSelected", isRecordSelected(), !isRecordSelected());
        setSaveNeeded(false);
        setCancelSelected(false);
        setNewRow(true);
    }

    protected final void defaultAllComboBox() {
        jcbCategoryFilm.setSelectedIndex(DEFAULT_INDEX_COMBO);
        jcbVersionFilm.setSelectedIndex(DEFAULT_INDEX_COMBO);
    }

    protected final void loadFields() {
        try {
            if (_films == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int maxSize = _films.size();
            int selectedRow = jtbFilms.getSelectedRow(); //row which you select into JTable
            if (selectedRow > maxSize) {
                throw new Exception(ERR_SELECT_OUTOFBOUND);
            }
            Phim selectedFilm = _films.get(selectedRow);
            if (selectedFilm == null) {
                throw new Exception(ERR_SELECTED_TYPE_EMPTY);
            }
            jtfCodeFilm.setText(selectedFilm.getCodePhim());
            jtfNameFilm.setText(selectedFilm.getTenPhim());
            jtfActorFilm.setText(selectedFilm.getDienVien());
            jtfStudioFilm.setText(selectedFilm.getHangPhim());
            jtfNationalFilm.setText(selectedFilm.getNuocSanXuat());
            setSelectedVersions(selectedFilm.getPhienBan());
            Loaiphim cachedCategory = selectedFilm.getLoaiphim();
            if (cachedCategory != null) {
                setSelectedCategory(cachedCategory.getTenLoaiPhim());
            }
            jtfDurationFilm.setText(selectedFilm.getThoiLuong().toString());
            jtfPirceFilm.setText(selectedFilm.getThoiLuong().toString());
            jdcStartDateFilm.setDate(selectedFilm.getNgayCongChieu());
            jtaDescriptionFilm.setText(selectedFilm.getMoTa());
        } catch (Exception e) {
            //System.out.println(String.format("Error: %s", e.getMessage()));
            e.printStackTrace(); //-->>> show remove this code
        }
    }

    protected final void loadFilms() throws Exception {
        _filmModel = (DefaultTableModel) jtbFilms.getModel();
        _filmModel.getDataVector().clear();
        try {
            _films = PhimDAO.getPhims();
            if (_films == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int count = 0;
            for (Phim phim : _films) {
                Vector v = new Vector();
                count = count + 1;
                v.addElement(count);
                v.addElement(phim.getCodePhim());
                v.addElement(phim.getTenPhim());
                v.addElement(phim.getLoaiphim().getTenLoaiPhim());
                _filmModel.addRow(v);
            }
            jtbFilms.setModel(_filmModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        } finally {
            PhimDAO.closeCurrentSession();
        }
    }

    protected final void loadVersions() throws Exception {
        DefaultComboBoxModel _cbVersionModel = (DefaultComboBoxModel) jcbVersionFilm.getModel();
        _cbVersionModel.removeAllElements();
        _versions = ClassUtils.getAllVersions();
        if (_versions == null || _versions.size() < 1) {
            throw new Exception(ERR_LIST_VERSIONS_EMPTY);
        }
        for (ClassUtils.FilmVersions item : _versions) {
            _cbVersionModel.addElement(item.getMsgLong());
        }
        jcbVersionFilm.setModel(_cbVersionModel);
    }

    protected final void loadCategories() throws Exception {
        DefaultComboBoxModel _cbCategoryModel = (DefaultComboBoxModel) jcbCategoryFilm.getModel();
        _cbCategoryModel.removeAllElements();
        _categories = LoaiPhimDAO.getLoaiPhims();
        if (_categories == null || _categories.size() < 1) {
            throw new Exception(ERR_LIST_CATEGORIES_EMPTY);
        }
        for (Loaiphim loaiphim : _categories) {
            _cbCategoryModel.addElement(loaiphim.getTenLoaiPhim());
        }
        jcbCategoryFilm.setModel(_cbCategoryModel);
    }

    protected final ClassUtils.FilmVersions getSelectedVersions() throws Exception {
        ClassUtils.FilmVersions version = null;
        if (_versions == null || _versions.size() < 1) {
            throw new Exception(ERR_LIST_VERSIONS_EMPTY);
        }
        int selectedIndex = jcbVersionFilm.getSelectedIndex();
        version = _versions.get(selectedIndex);
        return version;
    }

    protected final Loaiphim getSelectedCategory() throws Exception {
        Loaiphim film = null;
        if (_categories == null || _categories.size() < 1) {
            throw new Exception(ERR_LIST_CATEGORIES_EMPTY);
        }
        int selectedIndex = jcbCategoryFilm.getSelectedIndex();
        film = _categories.get(selectedIndex);
        return film;
    }

    protected final void setSelectedVersions(String msgVersion) throws Exception {
        if (msgVersion.isEmpty()) {
            throw new Exception(ERR_INVALID_PARAMS);
        }
        if (_versions == null || _versions.size() < 1) {
            throw new Exception(ERR_LIST_VERSIONS_EMPTY);
        }
        boolean foundFlag = false;
        int searchIndex = -1;
        int maxSize = _versions.size();
        for (ClassUtils.FilmVersions item : _versions) {
            searchIndex++;
            if (item.getMsgLong().equalsIgnoreCase(msgVersion)) {
                foundFlag = true;
                break;
            }
        }
        searchIndex = (!foundFlag) ? DEFAULT_INDEX_COMBO : searchIndex;
        jcbVersionFilm.setSelectedIndex(searchIndex);
    }

    protected final void setSelectedCategory(String nameCategory) throws Exception {
        if (nameCategory.isEmpty()) {
            throw new Exception(ERR_INVALID_PARAMS);
        }
        if (_categories == null || _categories.size() < 1) {
            throw new Exception(ERR_LIST_CATEGORIES_EMPTY);
        }
        boolean foundFlag = false;
        int searchIndex = -1;
        int maxSize = _categories.size();
        for (Loaiphim item : _categories) {
            searchIndex++;
            if (item.getTenLoaiPhim().equalsIgnoreCase(nameCategory)) {
                foundFlag = true;
                break;
            }
        }
        searchIndex = (!foundFlag) ? DEFAULT_INDEX_COMBO : searchIndex;
        jcbCategoryFilm.setSelectedIndex(searchIndex);
    }

    protected final int getFilmByCode(String code) throws Exception {
        if (code.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_films == null || _films.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _films.size();
        for (Phim phim : _films) {
            searchIndex++;
            if (phim.getCodePhim().equalsIgnoreCase(code)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final int getFilmByName(String name) throws Exception {
        if (name.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_films == null || _films.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _films.size();
        for (Phim phim : _films) {
            searchIndex++;
            if (phim.getTenPhim().equalsIgnoreCase(name)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final void setSelectedRowFilm(int index) {
        if (index == -1) {
            return;
        }
        jtbFilms.changeSelection(index, 0, false, false);
    }

    protected final Phim getSelectedFilm() throws Exception {
        Phim cachedFilm = null;
        if (!isRecordSelected()) {
            throw new Exception(ERR_NOT_SELECTED_FILM);
        }
        if (_films == null || _films.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int selectedIndex = jtbFilms.getSelectedRow();
        cachedFilm = _films.get(selectedIndex);
        return cachedFilm;
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Change Images Task" >

    private class ChangeImageTask extends Task<Void, Void> {

        public ChangeImageTask() {
            super(localApplication);
        }

        @Override
        protected Void doInBackground() throws Exception {
            // Get selected film
            Phim cachedFillm = getSelectedFilm();
            // Get images from this selected film
            List<Hinhanh> images = HinhAnhDAO.getHinhAnhsByFilm(cachedFillm);
            Hinhanh cachedImage = (!images.isEmpty()) ? images.get(0) : null;
            // Show image dialog
            if (_imagesDialog == null) {
                JFrame mainFrame = MainFormApp.getApplication().getMainFrame();
                _imagesDialog = new AdminImageDialog(mainFrame, true, cachedImage);
                _imagesDialog.setLocationRelativeTo(mainFrame);
                // Set selected film
                _imagesDialog.setOwnedFilm(cachedFillm);
                // Set images if they not null
            } else {
                _imagesDialog.setOwnedFilm(cachedFillm);
                _imagesDialog.setOwnedImage(cachedImage);
                _imagesDialog.setUpdateState(AdminImageDialog.UPDATE_STATE);
                _imagesDialog.loadImage();
            }
            MainFormApp.getApplication().show(_imagesDialog);
            // Get result from closed dialog
            int result = _imagesDialog.getActionResult();
            // User cancel not change image
            if (result == AdminImageDialog.CANCEL_OPTION) {
                setMessage(String.format("%d", result));
                return null;
            }else if (result == AdminImageDialog.DELETE_OPTION){
                HinhAnhDAO.deleteHinhAnhs(cachedImage);
                return null;
            }
            String codeImage = _imagesDialog.getCodeImage();
            String urlImage = (_imagesDialog.getImageFile() != null) ? _imagesDialog.getImageFile().getAbsolutePath() : "url empty";
            setMessage(String.format("%d - %s - %s", result, codeImage, urlImage));
            // Copy above film into default image folder            
//            String destDirectory = String.format("%s\\publicImages", ClassUtils.getCurrentApplication());
//            String destDirectory =  ClassUtils.getCurrentApplication();
//            int resultCopy = ClassUtils.copyFileToDirectory(sourceFile, destDirectory);
//            if (resultCopy == ClassUtils.COPY_SUCCESS){
//                setMessage("Copy success !");
//            }else {s
//                setMessage("Copy failed !");
//            }
            // Prepare object to save it database
            if (_imagesDialog.getUpdateState() == AdminImageDialog.UPDATE_STATE) {
                cachedImage.setCodeHinhAnh(codeImage);
                cachedImage.setDuongDan(urlImage);
                HinhAnhDAO.updateHinhAnhs(cachedImage);
            } else {
                Hinhanh savedImage = new Hinhanh(cachedFillm, codeImage, urlImage,
                        ClassUtils.IMAGE_AVATAR, ClassUtils.StateFields.DEFAULT_STATUS);
                // Save it into hinh anh tables
                HinhAnhDAO.insertHinhAnhs(savedImage);
            }
            return null;
        }

        @Override
        protected void cancelled() {
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
            thrwbl.printStackTrace();// >>> Remember remove its
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_UPLOAD_IMAGES_SUCCESS);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Search Task" >

    private class SearchTask extends Task<Void, Void> {

        public SearchTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SEARCH_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 3);
            // Check text field to input text not empty or default text
            String searchField = jtfSearch.getText();
            int resultIndex = -1;
            // Check option search to be checked
            if (jrdByCode.isSelected()) {
                resultIndex = getFilmByCode(searchField);
            } else if (jrdByName.isSelected()) {
                resultIndex = getFilmByName(searchField);
            }
            // Get object is selected
            if (resultIndex == -1) {
                throw new Exception(String.format(ERR_SEARCH_NOT_FOUND, searchField));
            }
            // Search database
            setSelectedRowFilm(resultIndex);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(2, 0, 3);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SEARCH_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
            clearAllTextField();
            defaultButtonState();
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SEARCH_SUCCESS);
            setProgress(3, 0, 3);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Delete Task" >

    private class DeleteTask extends Task<Void, Void> {

        public DeleteTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_DELETE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get object is selected to delete
            int selectedIndex = jtbFilms.getSelectedRow();
            if (_films == null || selectedIndex == -1) {
                throw new Exception(ERR_DELETE_INVALID_PARAMS);
            }
            Phim cachedFilm = _films.get(selectedIndex);
            String msg = String.format(MSG_DELETE_CONFIRM, cachedFilm.getCodePhim());
            int returnOptionDialog = JOptionPane.showConfirmDialog(localApplication.getMainFrame(), msg, MSG_DELETE_TITLE, JOptionPane.OK_CANCEL_OPTION);
            if (returnOptionDialog == JOptionPane.CANCEL_OPTION) {
                return null;
            }
            setMessage(MSG_DELETE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Delete database
            PhimDAO.deletePhims(cachedFilm);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_DELETE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_DELETE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Update Task" >

    private class UpdateTask extends Task<Void, Void> {

        public UpdateTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_UPDATE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get information and prepare object
            int selectedIndex = jtbFilms.getSelectedRow();
            if (_films == null || selectedIndex == -1) {
                throw new Exception(ERR_UPDATE_INVALID_PARAMS);
            }
            Phim cachedFilm = _films.get(selectedIndex);

            String codeFilm = jtfCodeFilm.getText();
            String nameFilm = jtfNameFilm.getText();
            String actorFilm = jtfActorFilm.getText();
            String studioFilm = jtfStudioFilm.getText();
            String nationalFilm = jtfNationalFilm.getText();
            ClassUtils.FilmVersions versionFilm = getSelectedVersions();
            Loaiphim categoryFilm = getSelectedCategory();
            String durationFilm = jtfDurationFilm.getText();
            String priceFilm = jtfPirceFilm.getText();
            Date startDateFilm = jdcStartDateFilm.getDate();
            String descriptionFilm = jtaDescriptionFilm.getText();

            cachedFilm.setCodePhim(codeFilm);
            cachedFilm.setTenPhim(nameFilm);
            cachedFilm.setDienVien(actorFilm);
            cachedFilm.setHangPhim(studioFilm);
            cachedFilm.setNuocSanXuat(nationalFilm);
            cachedFilm.setPhienBan(versionFilm.getMsgLong());
            cachedFilm.setLoaiphim(categoryFilm);
            cachedFilm.setThoiLuong(Integer.parseInt(durationFilm));
            cachedFilm.setGiaCoBan(Float.parseFloat(priceFilm));
            cachedFilm.setNgayCongChieu(startDateFilm);
            cachedFilm.setMoTa(descriptionFilm);

            setMessage(MSG_UPDATE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Update to database
            PhimDAO.updatePhims(cachedFilm);
            // Loading gui
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_UPDATE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_UPDATE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Save Task" >

    private class SaveTask extends Task<Void, Void> {

        public SaveTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SAVE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get all information from fields
            String codeFilm = jtfCodeFilm.getText();
            String nameFilm = jtfNameFilm.getText();
            String actorFilm = jtfActorFilm.getText();
            String studioFilm = jtfStudioFilm.getText();
            String nationalFilm = jtfNationalFilm.getText();
            ClassUtils.FilmVersions versionFilm = getSelectedVersions();
            Loaiphim categoryFilm = getSelectedCategory();
            String durationFilm = jtfDurationFilm.getText();
            String priceFilm = jtfPirceFilm.getText();
            Date startDateFilm = jdcStartDateFilm.getDate();
            String descriptionFilm = jtaDescriptionFilm.getText();

            // Prepare object
            Phim film = new Phim(categoryFilm, codeFilm, nameFilm,
                    actorFilm, studioFilm, nationalFilm,
                    descriptionFilm, versionFilm.getMsgLong(), Integer.parseInt(durationFilm),
                    Float.parseFloat(priceFilm), startDateFilm, StateFields.DEFAULT_STATUS,
                    null, null);
            setMessage(MSG_SAVE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Save into database
            PhimDAO.insertPhims(film);
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilms();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SAVE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SAVE_SUCCESS);
            setProgress(4, 0, 4);
//            clearAllTextField();
            defaultButtonState();
        }
    }
    // </editor-fold>

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupOption = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jtfSearch = new javax.swing.JTextField();
        jbtnSearch = new javax.swing.JButton();
        jrdByCode = new javax.swing.JRadioButton();
        jrdByName = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbFilms = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jpScrollDetailFilm = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfCodeFilm = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfNameFilm = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfActorFilm = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfStudioFilm = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfNationalFilm = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfDurationFilm = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtfPirceFilm = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtaDescriptionFilm = new javax.swing.JTextArea();
        jcbVersionFilm = new javax.swing.JComboBox();
        jcbCategoryFilm = new javax.swing.JComboBox();
        jdcStartDateFilm = new com.toedter.calendar.JDateChooser();
        jbtnChangeImages = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jbtnCancel = new javax.swing.JButton();
        jbtnDelete = new javax.swing.JButton();
        jbtnUpdate = new javax.swing.JButton();
        jbtnAdd = new javax.swing.JButton();
        jbtnReset = new javax.swing.JButton();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminFilm"); // NOI18N
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpSearchForm.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jtfSearch.setText(bundle.getString("jtfSearchFilm.title")); // NOI18N
        jtfSearch.setName("jtfSearch"); // NOI18N

        jbtnSearch.setText(bundle.getString("jbtnSearch.title")); // NOI18N
        jbtnSearch.setName("jbtnSearch"); // NOI18N

        groupOption.add(jrdByCode);
        jrdByCode.setSelected(true);
        jrdByCode.setText(bundle.getString("jrdCodeFilm.title")); // NOI18N
        jrdByCode.setName("jrdByCode"); // NOI18N

        groupOption.add(jrdByName);
        jrdByName.setText(bundle.getString("jrdNameFilm.title")); // NOI18N
        jrdByName.setName("jrdByName"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jrdByCode)
                        .addGap(18, 18, 18)
                        .addComponent(jrdByName))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jtfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(82, 82, 82)
                        .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrdByCode)
                    .addComponent(jrdByName))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpListFilm.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtbFilms.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nums", "Code", "Name", "Category"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbFilms.setName("jtbFilms"); // NOI18N
        jScrollPane1.setViewportView(jtbFilms);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpFilmDetailForm.title"))); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jpScrollDetailFilm.setName("jpScrollDetailFilm"); // NOI18N

        jLabel1.setText(bundle.getString("jlbCodeFilm.title")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jtfCodeFilm.setName("jtfCodeFilm"); // NOI18N

        jLabel2.setText(bundle.getString("jlbNameFilm.title")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jtfNameFilm.setName("jtfNameFilm"); // NOI18N

        jLabel3.setText(bundle.getString("jlbActor.title")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jtfActorFilm.setName("jtfActorFilm"); // NOI18N

        jLabel4.setText(bundle.getString("jlbStudioFilm.title")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jtfStudioFilm.setName("jtfStudioFilm"); // NOI18N

        jLabel5.setText(bundle.getString("jlbNationalFilm.title")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jtfNationalFilm.setName("jtfNationalFilm"); // NOI18N

        jLabel6.setText(bundle.getString("jlbVersionFilm.title")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(bundle.getString("jlbCategoryFilm.title")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jtfDurationFilm.setName("jtfDurationFilm"); // NOI18N

        jLabel8.setText(bundle.getString("jlbDurateFilm.title")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jtfPirceFilm.setName("jtfPirceFilm"); // NOI18N

        jLabel9.setText(bundle.getString("jlbOriginalPrice.title")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(bundle.getString("jlbStartingDate.title")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(bundle.getString("jlbDetaildFilm.title")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jtaDescriptionFilm.setColumns(20);
        jtaDescriptionFilm.setRows(5);
        jtaDescriptionFilm.setName("jtaDescriptionFilm"); // NOI18N
        jScrollPane3.setViewportView(jtaDescriptionFilm);

        jcbVersionFilm.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbVersionFilm.setName("jcbVersionFilm"); // NOI18N

        jcbCategoryFilm.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbCategoryFilm.setName("jcbCategoryFilm"); // NOI18N

        jdcStartDateFilm.setName("jdcStartDateFilm"); // NOI18N

        jbtnChangeImages.setText(bundle.getString("jbtnChangeImage.text")); // NOI18N
        jbtnChangeImages.setName("jbtnChangeImages"); // NOI18N

        javax.swing.GroupLayout jpScrollDetailFilmLayout = new javax.swing.GroupLayout(jpScrollDetailFilm);
        jpScrollDetailFilm.setLayout(jpScrollDetailFilmLayout);
        jpScrollDetailFilmLayout.setHorizontalGroup(
            jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpScrollDetailFilmLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpScrollDetailFilmLayout.createSequentialGroup()
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(26, 26, 26)
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfStudioFilm, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfActorFilm, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfCodeFilm, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfNameFilm, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpScrollDetailFilmLayout.createSequentialGroup()
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcbVersionFilm, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jtfNationalFilm, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(jbtnChangeImages, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(119, 119, 119)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jpScrollDetailFilmLayout.createSequentialGroup()
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addGap(54, 54, 54)
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jdcStartDateFilm, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jtfDurationFilm, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(jtfPirceFilm, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                            .addComponent(jcbCategoryFilm, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jpScrollDetailFilmLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(62, 62, 62))
        );
        jpScrollDetailFilmLayout.setVerticalGroup(
            jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpScrollDetailFilmLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfCodeFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jcbCategoryFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfNameFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jtfDurationFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtfActorFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jtfPirceFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jtfStudioFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10))
                    .addComponent(jdcStartDateFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpScrollDetailFilmLayout.createSequentialGroup()
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfNationalFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jpScrollDetailFilmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbVersionFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addComponent(jbtnChangeImages))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jScrollPane2.setViewportView(jpScrollDetailFilm);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpAction.title"))); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jbtnCancel.setText(bundle.getString("jbtnCancel.title")); // NOI18N
        jbtnCancel.setName("jbtnCancel"); // NOI18N

        jbtnDelete.setText(bundle.getString("jbtnDeleteFilm.title")); // NOI18N
        jbtnDelete.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jbtnDelete.setName("jbtnDelete"); // NOI18N

        jbtnUpdate.setText(bundle.getString("jbtnUpdateFilm.title")); // NOI18N
        jbtnUpdate.setName("jbtnUpdate"); // NOI18N

        jbtnAdd.setText(bundle.getString("jbtnAddFilm.title")); // NOI18N
        jbtnAdd.setName("jbtnAdd"); // NOI18N

        jbtnReset.setText(bundle.getString("jbtnReset.title")); // NOI18N
        jbtnReset.setName("jbtnReset"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(88, 88, 88)
                .addComponent(jbtnReset, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jbtnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jbtnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jbtnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jbtnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(101, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnReset)
                    .addComponent(jbtnAdd)
                    .addComponent(jbtnUpdate)
                    .addComponent(jbtnDelete)
                    .addComponent(jbtnCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup groupOption;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JButton jbtnAdd;
    private javax.swing.JButton jbtnCancel;
    private javax.swing.JButton jbtnChangeImages;
    private javax.swing.JButton jbtnDelete;
    private javax.swing.JButton jbtnReset;
    private javax.swing.JButton jbtnSearch;
    private javax.swing.JButton jbtnUpdate;
    private javax.swing.JComboBox jcbCategoryFilm;
    private javax.swing.JComboBox jcbVersionFilm;
    private com.toedter.calendar.JDateChooser jdcStartDateFilm;
    private javax.swing.JPanel jpScrollDetailFilm;
    private javax.swing.JRadioButton jrdByCode;
    private javax.swing.JRadioButton jrdByName;
    private javax.swing.JTextArea jtaDescriptionFilm;
    private javax.swing.JTable jtbFilms;
    private javax.swing.JTextField jtfActorFilm;
    private javax.swing.JTextField jtfCodeFilm;
    private javax.swing.JTextField jtfDurationFilm;
    private javax.swing.JTextField jtfNameFilm;
    private javax.swing.JTextField jtfNationalFilm;
    private javax.swing.JTextField jtfPirceFilm;
    private javax.swing.JTextField jtfSearch;
    private javax.swing.JTextField jtfStudioFilm;
    // End of variables declaration//GEN-END:variables
}
